package edu.compila.client;


import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.user.client.History;
import com.google.gwt.user.client.ui.RootPanel;
import com.google.gwt.user.client.ui.SimplePanel;

import edu.compila.client.api.HistoryManager;
import edu.compila.client.api.Tela;

public class MyEntryPoint implements EntryPoint {
	
	private final SimplePanel mainPanel = new SimplePanel();

	private HistoryManager historyManager = new HistoryManager(mainPanel);

	public void onModuleLoad() {
		registrarTelas();
    	checaHistory();
    	esconderLoading();
    }

	public void registrarTelas() {
		addTela(TesteTela.init());
		addTela(SobreTela.init());
	}
	
	//Checa se é um link composto ou o home
	private void checaHistory(){
        //Verificando se há algum token
        if(History.getToken().isEmpty()){
            //Exibindo o home:
			History.newItem("teste");
        } else {
        	History.fireCurrentHistoryState();
        }
	}

	public void addTela(Tela tela){
		historyManager.adicionar(tela);
	}
	
	//Esconde o loading do html
	private void esconderLoading(){
		RootPanel.get("aguarde").setVisible(false);
		RootPanel.get("main").add(mainPanel);
	}

}
